
<div <?php if ($this->params->id != "") echo 'id="' . $this->params->id . '" '; ?>class="yahoo_calendar<?php echo $this->params->css_suffix; ?>">
	
	<div>
		<input type="text" name="<?php echo $this->params->input_name; ?>" id="<?php echo $this->params->input_name; ?>" value="<?php echo $this->input_default_value; ?>">
	</div>

	<div id="calendar_<?php echo $this->params->input_name; ?>"></div>
	
	
	<script type="text/javascript">
		
		YAHOO.namespace("example.calendar.<?php echo $this->params->input_name; ?>");
		
		YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.init = function()
		{
			
			function handleSelect(type,args,obj)
			{
				var dates = args[0]; 
				var date = dates[0];
				var year = date[0], month = date[1], day = date[2];
				
				var txtDate1 = document.getElementById("<?php echo $this->params->input_name; ?>");	// textfield of the input
				txtDate1.value = day + "/" + month + "/" + year;
			}
			
			function updateCal()
			{
				var txtDate1 = document.getElementById("<?php echo $this->params->input_name; ?>");	// textfield of the input

				if (txtDate1.value != "")
				{
					YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.cal.select(txtDate1.value);
					var selectedDates = YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.cal2.getSelectedDates();
					if (selectedDates.length > 0)
					{
						var firstDate = selectedDates[0];
						YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.cal.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear());
						YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.cal.render();
					}
					else
					{
						alert("Por favor, seleccione entre fechas disponibles.");
					}

				}
			}

			// For this example page, stop the Form from being submitted, and update the cal instead
			function handleSubmit(e)
			{
				updateCal();
				YAHOO.util.Event.preventDefault(e);
			}
			
			YAHOO.example.calendar.<?php echo $this->params->input_name; ?> = new YAHOO.widget.Calendar(
				"cal",
				"calendar_<?php echo $this->params->input_name; ?>",		// the div which will be used to render the calendar
				{ LOCALE_WEEKDAYS:"short", 
				  START_WEEKDAY: 1,
				  MULTI_SELECT: false,
				  mindate:"<?php echo $this->params->calendar_min_date; ?>",	// the date from which the calendar can be selected
				  maxdate:"<?php echo $this->params->calendar_max_date; ?>"	// the date until the calendar can be selected
				 }
			);

			// Correct formats for Spanish: dd/mm/yyyy, dd/mm, mm/yyyy

			YAHOO.example.calendar.cal2.cfg.setProperty("DATE_FIELD_DELIMITER", "/");

			YAHOO.example.calendar.cal2.cfg.setProperty("MDY_DAY_POSITION", 1);
			YAHOO.example.calendar.cal2.cfg.setProperty("MDY_MONTH_POSITION", 2);
			YAHOO.example.calendar.cal2.cfg.setProperty("MDY_YEAR_POSITION", 3);

			YAHOO.example.calendar.cal2.cfg.setProperty("MD_DAY_POSITION", 1);
			YAHOO.example.calendar.cal2.cfg.setProperty("MD_MONTH_POSITION", 2);
			
			// Date labels for Spanish locale

			YAHOO.example.calendar.cal2.cfg.setProperty("MONTHS_SHORT",   ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"]);
			YAHOO.example.calendar.cal2.cfg.setProperty("MONTHS_LONG",    ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]);
			YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_1CHAR", ["D", "L", "M", "X", "J", "V", "S"]);
			YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_SHORT", ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"]);
			YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_MEDIUM",["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"]);
			YAHOO.example.calendar.cal2.cfg.setProperty("WEEKDAYS_LONG",  ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado"]);

			//YAHOO.example.calendar.cal2.cfg.setProperty("PAGEDATE", "<3/2010"); //indica el mes/año en los que se muestra inicialmente el calendario

			YAHOO.example.calendar.<?php echo $this->params->input_name; ?>.cal.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.<?php echo $this->params->calendar_min_date; ?>.cal, true);
			YAHOO.example.calendar.<?php echo $this->params->calendar_min_date; ?>.cal1.render();
			
			YAHOO.util.Event.addListener("update", "click", updateCal);
			YAHOO.util.Event.addListener("dates", "submit", handleSubmit);
		}

		YAHOO.util.Event.onDOMReady(YAHOO.example.calendar.<?php echo $this->params->calendar_min_date; ?>.init);
		
    </script>

</div>
